Page({
    data: {
        title: "中心性肥胖标准测试",
        brief: '明星都在学习的健康知识秘籍，今天全部免费教你',
        img: 'http://fcdn.qiushilaile.com/game/default-2111621235012128.png',
        healthNum: 11,
        desc: '明星都在学习的健康知识秘籍，今天全部免费教你',
        goodsId: 'jianfei',
        timu: [{
            question: "您的性别是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-29991611050055611.jpg",
            options: [{
                leap: "A",
                option: "男生",
                fs: 0,
            }, {
                leap: "B",
                option: "女生",
                fs: 0,
            }]
        }, {
            question: "您的腰围是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-14601611050074691.jpg",
            options: [{
                option: 0,
                fs: 0,
            }]
        }, {
            question: "您的臀围是？",
            imgUrl: "https://fcdn.qiushilaile.com/adx/qualificationMaterials-14601611050074691.jpg",
            options: [{
                option1: 0,
                fs: 0,
            }]
        }],
        array: ['40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
            '50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
            '60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
            '70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
            '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
            '90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
            '100'
        ], // 腰围
        arrayO: ['70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
            '80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
            '90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
            '100', '101', '102', '103', '104', '105', '106', '107', '108', '109',
            '110', '111', '112', '113', '114', '115', '116', '117', '118', '119',
            '120'
        ], // 臀围
        progress: 0,
        choiceArray: [],
        commentList: [{
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-86481625544662634.png',
            comment: '测试结果这么准的吗'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-32181625544694629.png',
            comment: '没想到啊没想到'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-16911625544715042.png',
            comment: '啦啦啦啦啦啦啦'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-86481625544662634.png',
            comment: '建议重生 呜呜呜呜'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-32181625544694629.png',
            comment: ' 原来我的数值这么高'
        }, {
            userPhoto: 'http://fcdn.qiushilaile.com/game/default-16911625544715042.png',
            comment: '哈哈哈哈哈哈我的还不错'
        }, ],
    },
    onLoad: function(options) {
        // console.log(this.data.title);
        // console.log(this.data.timu);
    },
    bindPickerChange(e) { // 身高picker选择器
        this.animate();
        console.log('picker发送选择改变，携带值为', e.detail.value);
        this.setData({
            index: e.detail.value,
            height: this.data.array[e.detail.value],
        })
        console.log('身高', this.data.array[e.detail.value]);
        if (this.data.toolNum == '5') {
            this.setData({
                layerPopup: true
            });
            return
        }
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
    },
    bindPickerChange1(e) { // 体重picker选择器
        console.log('picker发送选择改变，携带值为', e.detail.value);
        this.animate();
        this.setData({
            indexO: e.detail.value,
            weight: this.data.arrayO[e.detail.value],
        })
        console.log('体重', this.data.arrayO[e.detail.value]);
        // setTimeout(() => {
        this.setData({
            id: null,
            progress: this.data.progress + 1,
        });
        // }, 1000)
        // console.log(this.data.progress);
        if (this.data.progress == '3') {
            console.log('跳出弹窗观看视频进行跳转', '性别', this.data.sex, '身高', this.data.height, '体重', this.data.weight);
            this.setData({
                layerPopup: true
            })
        }
    },
    animate() {
        const animation = tt.createAnimation({
            duration: 500,
        });
        this.animation = animation;
        this.animation.opacity(0).translateX('400px').step({
            duration: 50,
        }).opacity(1).translateX('0px').step({
            duration: 1000,
        })
        this.setData({
            animationData: this.animation.export(),
        });
    },
    toResult() {
        let cos = this.data.height / this.data.weight
        const COS = (Math.round(cos * 100) / 100).toFixed(1)
        console.log(COS);
        if (this.data.sex == '男生') {
            console.log('man');
            if (COS > 1.00) {
                this.setData({
                    value: '中心性肥胖'
                })
            } else {
                this.setData({
                    value: '非中心性肥胖'
                })
            }
            tt.navigateTo({
                url: '/pages/result/result?tools=cos&value=' + this.data.value +
                    '&cos=' + this.data.height // 指定页面的url
            });
            // if (this.data.is_true == 1) {

            //     return
            // }
        }
        if (this.data.sex == '女生') {
            console.log('woman');
            if (COS > 0.90) {
                this.setData({
                    value: '中心性肥胖'
                })
            } else {
                this.setData({
                    value: '非中心性肥胖'
                })
            }
            tt.navigateTo({
                url: '/pages/result/result?tools=cos&cos=' + this.data.height +
                    '&value=' + this.data.value // 指定页面的url
            });
            // if (this.data.is_true == 1) {

            //     return
            // }

        }
    },
    itemClick(e) {
        // var index1 = e.currentTarget.dataset.fs
        // var indexArr = this.data.choiceArray
        // indexArr.push(index1)

        // this.setData({
        //     id: index1,
        //     choiceArray: indexArr // choiceArray用来存放选择的选项
        // })
        // console.log(this.data.choiceArray);

        // if ((this.data.progress + 1) == this.data.timu.length) { // 答完题跳转
        //   let sum = 0;
        //   let arr = this.data.choiceArray
        //   arr.forEach(item => {
        //     sum = sum + item
        //   })
        //   console.log(sum, 'sum跳转');
        //   this.setData({
        //     lookResultLayer: true,
        //   })
        //   return
        // }
        // setTimeout(() => {
        // if (this.data.progress == '0') {
        //     this.setData({
        //         id: null,
        //         progress: this.data.progress + 1
        //     });
        // }
        // }, 1000)
        this.setData({
            id: e.currentTarget.dataset.index,
            active: true,
        })
        console.log(e.currentTarget.dataset.index);
        if (this.data.progress == '0') {
            setTimeout(() => {
                this.animate();
                this.setData({
                    id: null,
                    sex: e.currentTarget.dataset.value,
                    progress: this.data.progress + 1
                });
                console.log(this.data.active);
            }, 500);

        }
    },
    closeClick() {
        // setTimeout(() => {
        this.setData({
            layerPopup: false,
        });
        wx.navigateBack({
            delta: 1
        });
        // }, 50);
    },
})